package org.zhb.querysql.model;

import java.io.Serializable;
import javax.persistence.*;
import javax.validation.constraints.NotNull;

import org.hibernate.annotations.DynamicUpdate;
import org.hibernate.annotations.GenericGenerator;

import com.fasterxml.jackson.annotation.JsonIgnore;

import java.util.List;

/**
 * The persistent class for the s_role database table.
 * 
 */
@Entity
@Table(name = "s_role")
@DynamicUpdate(true)
public class Role implements Serializable {
	private static final long serialVersionUID = 1L;

	@Id
	@Column(unique = true, nullable = false, length = 32)
	@GeneratedValue(generator = "uuid")
	@GenericGenerator(strategy = "uuid", name = "uuid")
	private String id;

	@Column(length = 200)
	private String description;

	@NotNull(message = "角色code不能为空!")
	@Column(name = "role_code", length = 40)
	private String roleCode;

	@NotNull(message = "角色名称不能为空!")
	@Column(name = "role_name", length = 40)
	private String roleName;

	// bi-directional many-to-one association to RoleFunction
	@OneToMany(mappedBy = "Role")
	private List<RoleFunction> RoleFunctions;

	// bi-directional many-to-one association to UserRole
	@OneToMany(mappedBy = "Role")
	private List<UserRole> UserRoles;

	public Role() {
	}

	public String getId() {
		return this.id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public String getDescription() {
		return this.description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	public String getRoleCode() {
		return this.roleCode;
	}

	public void setRoleCode(String roleCode) {
		this.roleCode = roleCode;
	}

	public String getRoleName() {
		return this.roleName;
	}

	public void setRoleName(String roleName) {
		this.roleName = roleName;
	}

	public List<RoleFunction> getRoleFunctions() {
		return this.RoleFunctions;
	}

	public void setRoleFunctions(List<RoleFunction> RoleFunctions) {
		this.RoleFunctions = RoleFunctions;
	}

	public RoleFunction addRoleFunction(RoleFunction RoleFunction) {
		getRoleFunctions().add(RoleFunction);
		RoleFunction.setRole(this);

		return RoleFunction;
	}

	public RoleFunction removeRoleFunction(RoleFunction RoleFunction) {
		getRoleFunctions().remove(RoleFunction);
		RoleFunction.setRole(null);

		return RoleFunction;
	}

	@JsonIgnore
	public List<UserRole> getUserRoles() {
		return this.UserRoles;
	}

	public void setUserRoles(List<UserRole> UserRoles) {
		this.UserRoles = UserRoles;
	}

	public UserRole addUserRole(UserRole UserRole) {
		getUserRoles().add(UserRole);
		UserRole.setRole(this);

		return UserRole;
	}

	public UserRole removeUserRole(UserRole UserRole) {
		getUserRoles().remove(UserRole);
		UserRole.setRole(null);

		return UserRole;
	}

}